package data.platform.merge.config;

import com.rabbitmq.client.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfig {

    @Value("${metric.merge.rabbitmq.host}")
    private String host;

    @Value("${metric.merge.rabbitmq.port}")
    private int port;

    @Value("${metric.merge.rabbitmq.virtualHost}")
    private String virtualHost;

    @Value("${metric.merge.rabbitmq.userName}")
    private String userName;

    @Value("${metric.merge.rabbitmq.password}")
    private String password;

    @Bean
    public Connection connection() throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(host);
        factory.setPort(port);
        factory.setUsername(userName);
        factory.setPassword(password);
        factory.setVirtualHost(virtualHost);
        factory.setAutomaticRecoveryEnabled(true);
        Connection connection = factory.newConnection();
        return connection;
    }
}
